package com.cloud.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.*;
import com.cloud.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.validation.constraints.Size;

/**
 * 角色表 sys_role
 *
 * @author yzj
 */
@Data
@Schema(name = "角色对象", description = "系统管理")
@TableName("sys_role")
public class SysRole extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @TableId(value = "role_id", type = IdType.AUTO)
    @Excel(name = "角色ID", orderNum = "1", width = 15)
    private Long roleId;

    @Schema(description = "系统编号", hidden = true)
    private String sysCode;

    @Schema(description = "角色名称")
    @Excel(name = "角色名称", orderNum = "2", width = 15)
    private String roleName;

    @Schema(description = "角色权限")
    @Excel(name = "角色权限", orderNum = "3", width = 15)
    private String roleKey;

    @Schema(description = "角色排序")
    @Excel(name = "角色排序", orderNum = "4", width = 10)
    private String roleSort;

    /**
     * 数据范围（1：所有数据权限；2：自定义数据权限；3：本部门数据权限；4：本部门及以下数据权限）
     */
    @Schema(description = "数据范围")
    @Excel(name = "数据权限", orderNum = "5", width = 15, replace = {"全部数据权限_1", "自定义数据权限_2",
            "本部门数据权限_3", "本部门及以下数据权限_4"})
    private String dataScope;

    @Schema(description = "用户ID", hidden = true)
    private Long userId;

    @Schema(description = "删除标识（0代表存在 1代表删除）", hidden = true)
    @TableField(value = "deleted", fill = FieldFill.INSERT)
    private Integer deleted;

    /**
     * 菜单树选择项是否关联显示（ 0：父子不互相关联显示 1：父子互相关联显示）
     */
    @Schema(description = "菜单树选择项是否关联显示")
    private boolean menuCheckStrictly;

    /**
     * 部门树选择项是否关联显示（0：父子不互相关联显示 1：父子互相关联显示 ）
     */
    @Schema(description = "部门树选择项是否关联显示")
    private boolean deptCheckStrictly;

    /**
     * 应用树选择项是否关联显示（0：父子不互相关联显示 1：父子互相关联显示 ）
     */
    @Schema(description = "应用树选择项是否关联显示")
    private boolean applyCheckStrictly;

    /**
     * 角色状态（0正常 1停用）
     */
    @Schema(description = "角色状态（0正常 1停用）")
    @Excel(name = "角色状态", orderNum = "6", width = 10, replace = {"正常_0", "停用_1"})
    private Integer status;

    @Schema(description = "用户是否存在此角色标识 默认不存在")
    @TableField(exist = false)
    private boolean flag = false;

    @Schema(description = "备注")
    @Excel(name = "备注", orderNum = "7", width = 20)
    private String remark;

    @Schema(description = "部门组（数据权限）", hidden = true)
    @TableField(exist = false)
    private Long[] deptIds;

    @Schema(description = "菜单组", hidden = true)
    @TableField(exist = false)
    private Long[] menuIds;

    @Schema(description = "应用组", hidden = true)
    @TableField(exist = false)
    private Long[] applyIds;

    public SysRole() {
    }

    public SysRole(Long roleId) {
        this.roleId = roleId;
    }

    @NotBlank(message = "角色名称不能为空")
    @Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符")
    public String getRoleName() {
        return roleName;
    }

    @Size(min = 0, max = 100, message = "权限字符长度不能超过100个字符")
    public String getRoleKey() {
        return roleKey;
    }

    @NotBlank(message = "显示顺序不能为空")
    public String getRoleSort() {
        return roleSort;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("roleId", getRoleId())
                .append("roleName", getRoleName())
                .append("roleKey", getRoleKey())
                .append("roleSort", getRoleSort())
                .append("dataScope", getDataScope())
                .append("menuCheckStrictly", isMenuCheckStrictly())
                .append("deptCheckStrictly", isDeptCheckStrictly())
                .append("status", getStatus())
                .append("deleted", getDeleted())
                .append("createBy", getCreateBy())
                .append("createTime", getCreateTime())
                .append("updateBy", getUpdateBy())
                .append("updateTime", getUpdateTime())
                .append("remark", getRemark())
                .toString();
    }
}
